package unsafe;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author lyx
 * @Date 2021/6/25 10:00
 */
public class MapList {
    public static void main(String[] args) {
        new Thread(()->{
            System.out.println("这只是一个测试");
        },"测试号线程").start();
        //记载因子,初始化容量 new HashMap<>(16,0.75);
        //Map<String, String > map = new HashMap<>(); //不安全
        Map<String , String > map = new ConcurrentHashMap<>(); //解决方案1,工具类

        for (int i = 0; i < 30; i++) {
            new Thread(()->{
                map.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0,10));
                System.out.println(map);
            },String.valueOf(i)).start();
        }
    }
}
